import React from "react";
import PropTypes from "prop-types";
import { Switch, Route, Redirect, routerRedux } from "dva/router";
import dynamic from "dva/dynamic";
import App from "routes/app";

const { ConnectedRouter } = routerRedux;

const Routers = function({ history, app }) {
  const error = dynamic({
    app,
    component: () => import("./routes/error")
  });
  const routes = [
    {
      path: "/dashboard",
      models: () => [import("./models/dashboard")],
      component: () => import("./routes/dashboard/")
    },
    {
      path: "/login",
      models: () => [import("./models/login")],
      component: () => import("./routes/login/")
    },
    {
      path: "/app/user",
      models: () => [import("./models/user")],
      component: () => import("./routes/user/")
    },
    {
      path: "/sys/manager",
      models: () => [import("./models/manager")],
      component: () => import("./routes/manager/")
    },
    {
      path: "/sys/menu",
      models: () => [import("./models/menu")],
      component: () => import("./routes/menu/")
    },
    {
      path: "/sys/role",
      models: () => [import("./models/role")],
      component: () => import("./routes/role/")
    },
    {
      path: "/sys/log",
      models: () => [import("./models/log")],
      component: () => import("./routes/log/")
    },

    {
      path: "/file/newfile",
      models: () => [import("./models/newfile")],
      component: () => import("./routes/newfile/")
    },

    {
      path: "/total/search",
      models: () => [import("./models/search")],
      component: () => import("./routes/search/")
    },
    {
      path: "/total/statistics",
      models: () => [import("./models/statistics")],
      component: () => import("./routes/statistics/")
    },

    {
      path: "/borrowManager/borrow",
      models: () => [import("./models/borrow"), import("./models/newfile")],
      component: () => import("./routes/loanMng/borrow")
    },
    {
      path: "/borrowManager/return",
      models: () => [import("./models/returns"), import("./models/fileChange")],
      component: () => import("./routes/loanMng/return")
    },

    {
      path: "/file/fileComponent",
      models: () => [import("./models/fileComponent")],
      component: () => import("./routes/fileComponent")
    },
    {
      path: "/file/fileChange",
      models: () => [import("./models/fileChange")],
      component: () => import("./routes/fileChange")
    },
    {
      path: "/file/fileTransfer",
      models: () => [import("./models/fileTransfer")],
      component: () => import("./routes/fileTransfer")
    },
    {
      path: "/file/fileDestroy",
      models: () => [import("./models/fileDestroy")],
      component: () => import("./routes/fileDestroy")
    },
    {
      path: "/borrowManager/archivalReminders",
      models: () => [import("./models/archivalReminders")],
      component: () => import("./routes/archivalReminders")
    },
    {
    	  path:'/sys/configManager',
    	  models:() => [import('./models/configManager')],
    	  component: () => import('./routes/configManager')
    },
    {
    	  path:'/sys/organization',
    	  models:() => [import('./models/organization')],
    	  component: () => import('./routes/organization')
    },
    {
    	  path:'/borrowManager/printing',
    	  models:() => [import('./models/printing')],
    	  component: () => import('./routes/printing')
    },
    {
        path:'/sys/message',
        models:() => [import('./models/message')],
    	  component: () => import('./routes/message')
    }
  ];

  return (
    <ConnectedRouter history={history}>
      <App>
        <Switch>
          <Route exact path="/" render={() => <Redirect to="/dashboard" />} />
          {routes.map(({ path, ...dynamics }, key) => (
            <Route
              key={key}
              exact
              path={path}
              component={dynamic({
                app,
                ...dynamics
              })}
            />
          ))}
          <Route component={error} />
        </Switch>
      </App>
    </ConnectedRouter>
  );
};

Routers.propTypes = {
  history: PropTypes.object,
  app: PropTypes.object
};

export default Routers;
